let { $, table, layer, form, upload } = layui;
export default class Delete {
    constructor(obj) {
        this.handle(obj);
    };

    handle(obj) {
        console.log(obj.data._id);
        function delOther(url) {
            $.ajax({
                type: 'get',
                url: url + '/all',
                success(res) {
                    for (let i of res.data) {
                        if (i.films == obj.data._id) {
                            $.ajax({
                                type: 'delete',
                                url: url + '/' + i._id,
                                success(response) {
                                    console.log(response);
                                }
                            })
                        }
                    }
                }
            })
        }
        layer.confirm('是否删除?', function (index) {
            console.log('obj.data:', obj.data);//里面的id为_id
            $.ajax({
                type: "delete",
                url: "/films/" + obj.data._id,
                success() {
                    layer.alert("删除成功")
                    table.reload("filmsTable", {
                        where: {}
                    });
                    layer.close(index);
                    delOther('/fac');
                    delOther('/soons');
                    delOther('/hotShow');
                    delOther('/hotPlay');
                }
            });
        });
    }
}